//
//  InfoViewController.m
//  Malena
//
//  Created by Wang Shuguang on 12-11-7.
//  Copyright (c) 2012年 Dawn. All rights reserved.
//

#import "InfoViewController.h"

@interface InfoViewController ()

@end

@implementation InfoViewController


- (void)viewDidUnload{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
	// Do any additional setup after loading the view.
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 45, 45);
    [self.view addSubview:button];
    
    if (self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - 50)];
    }else{
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_HEIGHT, SCREEN_WIDTH - 50)];
    }
    webView.scalesPageToFit = YES;
  
    [self.view addSubview:webView];
    [webView release];
    
    NSString *infoPath = RESOURCEFILE(@"Du_Yang", @"html");
    NSURL *url = [NSURL fileURLWithPath:infoPath];
   
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    
}

- (void)backButtonClick:(id)sender{
    
    if (IOSVersion_5) {
        [self.presentingViewController willRotateToInterfaceOrientation:self.presentingViewController.interfaceOrientation duration:0];
        [self.presentingViewController dismissViewControllerAnimated:YES completion:^{
            
            
        }];
    }else{
        [self.parentViewController dismissModalViewControllerAnimated:YES];
    }
}


#pragma mark -
#pragma mark UIViewControllerRotation
// 支持旋转
- (BOOL)shouldAutorotate{
    return YES;
}

// 支持所有的方向
- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
	return YES;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    
    //[UIView beginAnimations:@"Scroll" context:nil];
    //[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //[UIView setAnimationDuration:duration];
    switch (toInterfaceOrientation) {
        case UIInterfaceOrientationLandscapeLeft:{
            
        }
        case UIInterfaceOrientationLandscapeRight:{
            webView.frame = CGRectMake(0, 50, SCREEN_HEIGHT, SCREEN_WIDTH - 50);
            break;
        }
        case UIInterfaceOrientationPortrait:{
            
        }
        case UIInterfaceOrientationPortraitUpsideDown:{
            webView.frame = CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT - 50);
            break;
        }
        default:
            break;
    }
    //[UIView commitAnimations];
}


@end
